
#include"Player.h"
#include<time.h>
#include<random>
#include<conio.h>
#include<iomanip>
//should init everything to zero
Player::Player()
{
	m_moveDone=0;
}

// initializes all values to null
void Player::Init(eConsoleType a_iWhichConsole)
{
	// create  new pieces and initializes them
	for(int i=0;i<g_inumPieces;i++)
		m_pieceInfo[i]=new Piece();
	// marks the position for the upper-left hand corner for each console's start box
	XYZ yBoxStart, PCStart, FS3Start, WeeStart;
	yBoxStart = set(-80, 30, 188);
	PCStart =  set(190.5, 30, 90.5);
	FS3Start = set(86, 30, -186.5);
	WeeStart = set(-181, 30, -77.5);
	
	// pass in name of console
	m_consoleName=a_iWhichConsole;
	m_pieceToMove=0;
	m_cardsLeft=g_inumOfPlayerCards;
	m_cardBeingUsed=0;
	
	//temp until you find a better place
		//makes rand random
	srand((unsigned)(time(NULL)));
	//gives random cards until we make a shuffler
	for(int i=0;i<g_inumOfPlayerCards;i++)
	m_playersCards[i]=rand() %14;
	switch(m_consoleName)
	{
	case YBOX:
		m_pieceInfo[0]->Init(m_consoleName, ONE,	yBoxStart.x, yBoxStart.z);
		m_pieceInfo[1]->Init(m_consoleName, TWO,	yBoxStart.x - 35, yBoxStart.z);
		m_pieceInfo[2]->Init(m_consoleName, THREE,	yBoxStart.x, yBoxStart.z + 35);
		m_pieceInfo[3]->Init(m_consoleName, FOUR,	yBoxStart.x - 35, yBoxStart.z + 35);
		
		break;
	case PC:
		m_pieceInfo[0]->Init(m_consoleName, ONE,	PCStart.x, PCStart.z);
		m_pieceInfo[1]->Init(m_consoleName, TWO,	PCStart.x, PCStart.z + 35);
		m_pieceInfo[2]->Init(m_consoleName, THREE,	PCStart.x + 35, PCStart.z);
		m_pieceInfo[3]->Init(m_consoleName, FOUR,	PCStart.x + 35, PCStart.z + 35);
		break;
	case FS3:
		m_pieceInfo[0]->Init(m_consoleName, ONE,	FS3Start.x, FS3Start.z);
		m_pieceInfo[1]->Init(m_consoleName, TWO,	FS3Start.x, FS3Start.z - 35);
		m_pieceInfo[2]->Init(m_consoleName, THREE,	FS3Start.x + 35, FS3Start.z);
		m_pieceInfo[3]->Init(m_consoleName, FOUR,	FS3Start.x + 35, FS3Start.z - 35);
		break;
	case WEE:
		m_pieceInfo[0]->Init(m_consoleName, ONE,	WeeStart.x, WeeStart.z);
		m_pieceInfo[1]->Init(m_consoleName, TWO,	WeeStart.x, WeeStart.z - 35);
		m_pieceInfo[2]->Init(m_consoleName, THREE,	WeeStart.x - 35, WeeStart.z);
		m_pieceInfo[3]->Init(m_consoleName, FOUR,	WeeStart.x - 35, WeeStart.z - 35);
		break;
	}
	isEmpty=false;
	m_cardsUsed=0;
	
}	

bool Player::checkCards()
{
	static int count=0;
	bool empty=false;
	
		if (m_cardsUsed==14)
			empty=true;
		else
			empty=false;

		return empty;

}
//moves piece by number
bool Player::MovePiece(int a_pieceIndex, int a_moveBy)
{

	return m_pieceInfo[a_pieceIndex]->Move(a_moveBy);
}
// moves the piece by the amount passed, returns false if unable to move there
bool Player::safeMovement(int a_cardToUse,int a_consoleType,int a_pieceIndex)
{
	
		switch(a_consoleType)
		{
		case YBOX:
			if (abs(m_pieceInfo[a_pieceIndex]->m_iSquareIndex+a_cardToUse -63)<2) //needs fixing
				return true;
			break;
		case PC:
			
			if (m_pieceInfo[a_pieceIndex]->m_iSquareIndex +a_cardToUse<= 17)
				return true;
			break;
		case FS3:
			if (m_pieceInfo[a_pieceIndex]->m_iSquareIndex +a_cardToUse<= 32)
				return true;
			break;
		case WEE:
			if (m_pieceInfo[a_pieceIndex]->m_iSquareIndex +a_cardToUse<= 47)
				return true;
			break;
		default:
			return false;
			break;
		}

}
Player::~Player()
{
}